﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication4.Domain.Entity;
using WebApplication4.Entity;

namespace WebApplication4.Domain
{
    public class DbIntializerHelper
    {
        public static void Intialzer()
        {
            using(var db = new Admin1000DbContext())
            {
               var dbExist = db.Database.EnsureCreated();
                var tempFruits = db.Fruits.Any();

                if (!tempFruits)
                {
                    var fruits1 = new Fruits
                    {
                        FruitsName = "苹果",
                        Description = "大苹果"
                    };

                    var fruits2 = new Fruits
                    {
                        FruitsName = "雪梨",
                        Description = "大雪梨"
                    };
                    db.Fruits.Add(fruits1);
                    db.Fruits.Add(fruits2);
                    db.SaveChanges();

                    db.Prices.AddRange(new Price[]
                    {
                    new Price
                    {
                        Priceup = 6,
                        FruitsId = fruits1.Id
                    },

                    new Price
                    {
                        Priceup = 5,
                        FruitsId = fruits2.Id
                    },

                    });

                    db.SaveChanges();
                }


                
            }
        }
    }
}
